/**
 * Field value testing
**/
var FieldTest = {
    Update: function(string,type)
    {    	
    	switch(type)
    	{
    		case 'post-code':
    			string = string.replace(/[^0-9]/gi,'');
    			string= string.replace(/([0-9]{2,})+([0-9]{3,})/,"$1-$2");
    			break;
    		case 'phone':
    			string = string.replace(/[^0-9]/gi,'');
    			string=string.replace(/([0-9]{3,})+([0-9]{3,})+([0-9]{3,})/,"$1-$2-$3");
    			break;
    		case 'nip':
    			string = string.replace(/[^0-9]/gi,'');
    			string=string.replace(/([0-9]{3,})+([0-9]{2,})+([0-9]{2,})+([0-9]{3,})/,
    				"$1-$2-$3-$4");
    			break;
    		case 'fax':
    			string = string.replace(/[^0-9]/gi,'');
    			string=string.replace(/([0-9]{3,})+([0-9]{3,})+([0-9]{2,})+([0-9]{2,})/,
    				"$1-$2-$3-$4");
    			break;		
    		case 'nrb':			
    			string = string.replace(/[^0-9]/gi,'');
    			string=string.replace(/([0-9]{2,})+([0-9]{4,})+([0-9]{4,})+([0-9]{4,})+([0-9]{4,})+([0-9]{4,})+([0-9]{4,})/,
    				"$1-$2-$3-$4-$5-$6-$7");
    			break;		
    		case 'date':
    			string = string.replace(/[^0-9]/gi,'');			
    			string=string.replace(/(19[0-9][0-9]|20[0-9][0-9])(0[1-9]|1[012])(0[1-9]|3[012]|[12][0-9])/,
    				"$1-$2-$3");
    			break;
    		case 'clear':
    				string='';
    			break;
    		case 'percent':
    			if(string.length>0 && !string.match('[%]$')) string+='%';
    			break;
    		default: return null;
    	}
    	return string;
    },
    
    Check: function(string, type,escape)
    {    	    	
    	if(escape==true) string = string.replace(/[^0-9]/gi,'');
    	switch(type)
    	{
    		case 'e-mail':			
    				return string.match('^([a-z0-9]+(\_|\.*))+@+([a-z][a-z0-9\-]*)+\.+([A-z][a-z0-9]*)$');				
    		case 'post-code':
    			return string.match('^([0-9]){5,5}$');
    		case 'phone':
            {
                
    			return string.match('^([0-9]){9,9}$') || string.match('^\+[0-9]{1,2}[0-9]{9,9}$');
            }
    		case 'nip':
    			return string.match('^([0-9]){10,10}$');
    		case 'fax':
    			return string.match('^([0-9]){10,10}$');
    		case 'empty-input':
    			return string.length==0?null:string.length;		
    		case 'numeric':
    			return string.match('^(\-|[0-9])+([0-9]*)$');
    		case 'nrb':
    			return string.match('^([0-9]){26,26}$');
    		case 'password':
    			return string.match('^([A-z])+([0-9]){6,11}$');
    			break;
    		case 'imagesize':
    			return string.match('^[1-9]{1,1}[0-9]*x[0-9]*$');
    			break;
    		case 'date':
    			return string.match('^(19[0-9][0-9]|20[0-9][0-9])(0[1-9]|1[012])(0[1-9]|3[012]|[12][0-9])$');
    		case 'percent':
    			return string.match('^[1-9][0-9]*\%$');
    		default: return null;
    	}
    }
};